<template>
  <view>
    <!-- <view class="bg" v-if="waitShow"></view> -->
    <!-- <view class="no_data" v-if="status === 0">
      <image class="img_nodata" src="https://ainengli.meilianshuke.com/jkhx/no_physical.png"></image>
      <view class="text">我们需要根据您的体检报告</view>
      <view class="text">为您制定个性化健康管理方案</view>
      <view class="text green">请耐心等待体检报告，或预约体检</view>
      <view class="button" @tap="reservationCheckup">预约体检</view>
    </view> -->
    <view v-if="status == 1 || status == 0" class="empty">
      <image class="img" src="@/static/icons/im-empty.png" />
      <text class="text">开通健康管理会员才能使用此服务哦</text>
      <button class="btn" @tap="goMember">加入会员</button>
    </view>
    <view class="no_data" v-else-if="status === 2">
      <image class="img_nodata2" src="https://ainengli.meilianshuke.com/jkhx/no_risk.png"></image>
      <view class="text">请耐心等待，会尽快为您分配健康管理师</view>
    </view>
    <ConversationList v-else :List="conversationList"></ConversationList>
  </view>
</template>

<script lang="ts" setup>
import { onShow, onLoad } from '@dcloudio/uni-app'
import { queryAccount } from '../../api/index'
import { ref, computed } from 'vue'
import store from '@/store/index'
import ConversationList from './conversation-list/index.vue'

// 0 等待体检报告 1 等待购买vip 2 等待分配健管师 3 已分配健管师
const status = ref(0)

const conversationList = computed(() => {
  return store.state.im.sessionList
})

onShow(async () => {
  if (!store.state.im.connectStatus) {
    await store.dispatch('updatePatientInfo')
  } else {
    return
  }
  const patientInfo = store.state.userInfo.patientInfo
  if (patientInfo.reportState == false) {
    status.value = 0
  } else if (!patientInfo.isVip) {
    status.value = 1
  } else {
    status.value = 2
    queryAccount(store.state.userInfo.patientInfo.empi)
      .then((res) => {
        if (res.data.errorCode == 'TO_ASSIGN_MNG') {
          status.value = 2
        } else if (res.data.errorCode == 'SUCCESS') {
          const { accid, token, appId } = res.data
          store.dispatch('im/IM_CONNECT', {
            accid: accid,
            token: token,
            appId: appId
          })
          status.value = 3
        }
      })
      .catch((e) => {
        console.log(e)
      })
  }
})
const goMember = () => {
  uni.navigateTo({ url: '/packA/pages/buyMember/index?source=im' })
}
const reservationCheckup = () => {
  uni.navigateTo({ url: '/packA/pages/reservationPhysicalExamination/index' })
}
</script>

<style lang="scss" scoped>
@import '../styles/common.scss';
.bg {
  position: fixed;
  z-index: 1;
  background-color: #f3f7f8;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
page {
  height: 100vh;
  overflow: hidden;
}

.empty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 142rpx;
  height: 100vh;
  background: #fff;
  .img {
    width: 356rpx;
    height: 276rpx;
  }
  .text {
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    font-size: 32rpx;
    color: #222222;
    line-height: 58rpx;
    text-align: center;
    font-style: normal;
    text-transform: none;
    margin-top: 32rpx;
  }
  .btn {
    width: 558rpx;
    height: 88rpx;
    background: #00d1b6;
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 600;
    font-size: 32rpx;
    color: #ffffff;
    line-height: 88rpx;
    text-align: center;
    margin-top: 48rpx;
  }
}
.no_data {
  overflow: hidden;
  text-align: center;
  height: 100vh;
  background: #fff;
  .img_nodata {
    margin-top: 142rpx;
    margin-bottom: 32rpx;
    width: 336rpx;
    height: 276rpx;
  }
  .img_nodata2 {
    margin-top: 202rpx;
    margin-bottom: 70rpx;
    width: 336rpx;
    height: 196rpx;
  }
  .text {
    margin: 0 auto;
    width: 488rpx;
    font-weight: 500;
    font-size: 32rpx;
    color: #222222;
    line-height: 58rpx;
  }
  .green {
    color: #00d1b6;
  }
  .button {
    margin: 48rpx auto;
    width: 558rpx;
    height: 88rpx;
    line-height: 88rpx;
    text-align: center;
    background: #00d1b6;
    border-radius: 44rpx;
    font-weight: 600;
    font-size: 32rpx;
    color: #ffffff;
  }
}
</style>
